var baseConfig = require("../../baseConfig")
var utils = require("../../utils/utils")
Page({
  data: {
    tixianSuccessSumMoney: "",
    tixianList1: [{
      year_month_day: '2020-11-30 15:30:41',
      money: 66,
      status: 0,
    }, {
      year_month_day: '2021-01-30 15:30:41',
      money: 68,
      status: 1,
    }, {
      year_month_day: '2021-02-14 15:30:41',
      money: 88,
      status: 2,
    }],
  },
  onLoad: function (options) {
    // console.log(options);
    this.getDateData()
  },
  getData() {
    let that = this
    var openid = wx.getStorageSync('openid')
    // console.log(openid);
    if (openid != undefined) {
      wx.request({
        url: baseConfig.url + 'tuiwaApp/get_tixian_record_list',
        method: 'POST',
        data: {
          uid:  wx.getStorageSync('userInfo').id,
          loginUserId: openid,
          start_time: that.data.start_time,
          end_time: that.data.end_time,
        },
        header: {
          'Content-Type': 'application/x-www-form-urlencoded'
        },
        success: res => {
          console.log(res.data.data)
          this.setData({
            tixianSuccessSumMoney: res.data.data.tixianSuccessSumMoney,
            tixianList: res.data.data.tixianList,
          })
          console.log(this.data.tixianSuccessSumMoney);
        }
      })
    }
  },
  bindDateChange: function (e) { // 点击选择年月筛选提现记录
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      date: e.detail.value,
      appVersion: false,
    })
    let list = e.detail.value.split('-')
    let year = list[0];
    let month = list[1];
    this.getMonthFirstLastDay(year, month)
  },
  getMonthFirstLastDay(year, month) { // 获取本月第一天和最后一天
    var firstDay = new Date(year, month - 1, 1); //这个月的第一天
    var currentMonth = firstDay.getMonth(); //取得月份数
    var lastDay = new Date(firstDay.getFullYear(), currentMonth + 1, 0); //是0而不是-1
    let start_time = utils.formatDate(firstDay, 'yyyy-mm-dd')
    let end_time = utils.formatDate(lastDay, 'yyyy-mm-dd')
    console.log('first_last', start_time, end_time);
    this.setData({
      start_time: start_time,
      end_time: end_time,
    })
    console.log('start_end', this.data.yearMonth, this.data.start_time, this.data.end_time)
    this.getData();
  },
  getDateData: function (e) { // 进入页面默认年月
    var timestamp = Date.parse(new Date());
    var date = new Date(timestamp);
    var Y = date.getFullYear(); // 获取年 
    var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1); // 获取月
    var D = date.getDate() < 10 ? '0' + date.getDate() : date.getDate(); // 获取日
    const yearMonth = Y + '-' + M
    this.setData({
      yearMonth: yearMonth,
      date: yearMonth,
      year: Y,
      month: M,
      day: D,
    })
    this.getMonthFirstLastDay(Y, M)
  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})